package com.example.demo.controller;

import com.example.demo.Service.IAddressService;
import com.example.demo.core.Result;
import com.example.demo.entity.params.AddressCreateParam;
import com.example.demo.entity.params.AddressUpdateParam;
import com.example.demo.entity.vo.AddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @GetMapping("/list")
    public Result<AddressVo> list(HttpServletRequest request){

        return Result.success(addressService.select(request));

    }

    @PostMapping("/create")
    public Result create(@RequestBody AddressCreateParam addressCreateParam,HttpServletRequest request){
        return addressService.create(request, addressCreateParam) == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/update")
    public Result update(@RequestBody AddressUpdateParam addressUpdateParam){
        return addressService.update(addressUpdateParam) == 1 ? Result.success() : Result.error();
    }

    @DeleteMapping("/delete/{addressId}")
    public Result delete(@PathVariable Long addressId){
        return addressService.delete(addressId) == 1 ? Result.success() : Result.error();
    }



}
